package fr.p10.miage.m1.lehouarner.car1.td2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

public class Authentification {
	private Hashtable hash = new Hashtable();
	
	public Authentification() {
		this.remplirHashtable();
	}
	
	public static void chargement(){
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (Exception e) {
			System.err.println("Erreur lors du chargement du driver");
			System.exit(1);
		}
	}
	
	public boolean estReconnue(String login, String password){
		if(hash.get(login) != null)
			if((hash.get(login)).equals(password)){
				return true;
			}
			else
				return false;
		else
			return false;
	}
	
	public void remplirHashtable(){
		String login, password;
		try {
			Connection cx = DriverManager.getConnection("jdbc:oracle:thin:@miage03.dmiage.u-paris10.fr:1521:MIAGE", "maletell", "matthieu");
			Statement state = cx.createStatement();
			ResultSet rs = state.executeQuery("SELECT * FROM LOGPWD");
			while(rs.next()){
				login = rs.getString("LOGIN");
				password = rs.getString("PWD");
				hash.put(login, password);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
	}
	
	public static void main(String[] args) {
		
	}
}
